package com.rzico.push;


import com.rzico.push.android.*;
import com.rzico.push.ios.*;
import com.rzico.util.DateUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class UMengSdk {

	private String appkey = null;
	private String appMasterSecret = null;
	private String timestamp = null;

	private PushClient client = new PushClient();

	public UMengSdk(String key, String secret) {
		try {
			appkey = key;
			appMasterSecret = secret;
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
	

	public void sendAndroidCustomizedcast(String userId,String title,String ticker,String text,String sound) throws Exception {
		AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
		// TODO Set your alias here, and use comma to split them if there are multiple alias.
		// And if you have many alias, you can also upload a file containing these alias, then 
		// use file_id to send customized notification.
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		customizedcast.setExpireTime(sdf.format(DateUtils.addDate(new Date(), Calendar.HOUR,2)));
		customizedcast.setAlias(userId, "userId");
		customizedcast.setTicker(ticker);
		customizedcast.setTitle(title);
		customizedcast.setText(text);
		customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
		// TODO Set 'production_mode' to 'false' if it's a test device. 
		// For how to register a test device, please see the developer doc.
		customizedcast.setProductionMode(true);
		//厂商通道相关参数
		customizedcast.setChannelActivity("eeuiApp");
		customizedcast.setChannelProperties("eeuiApp");
		customizedcast.setPlaySound(true);
		if (sound!=null) {
			customizedcast.setSound(sound);
		}
		customizedcast.setPlayVibrate(true);
		customizedcast.setPlayLights(true);
		customizedcast.setAfterOpenAction(AndroidNotification.AfterOpenAction.go_app);
		client.send(customizedcast);
	}

	public void sendIOSCustomizedcast(String userId,String title,String ticker,String text,String sound) throws Exception {
		IOSCustomizedcast customizedcast = new IOSCustomizedcast(appkey,appMasterSecret);
		// TODO Set your alias and alias_type here, and use comma to split them if there are multiple alias.
		// And if you have many alias, you can also upload a file containing these alias, then 
		// use file_id to send customized notification.
		customizedcast.setAlias(userId, "userId");
		//customizedcast.setAlert("IOS 个性化测试");
		//alert的值设置为字典
		customizedcast.setAlert(ticker , title, text);
		customizedcast.setBadge( 0);
		if (sound!=null) {
			customizedcast.setSound(sound+".caf");
		}
        // TODO set 'production_mode' to 'true' if your app is under production mode

		customizedcast.setProductionMode(true);
		client.send(customizedcast);
	}

}
